package com.example.gallery;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;

import android.app.Activity;
import android.graphics.Bitmap;
import android.graphics.Bitmap.CompressFormat;
import android.util.DisplayMetrics;
import android.util.Log;

public class BitmapToFile extends Activity{
	FileOutputStream fos = null;
	final static String TAG = "BitmapToFile";
	DisplayMetrics metrix = new DisplayMetrics();

	
	int width ; 
	int height ;
	
	public void toFile(Bitmap mBitmap, String full_path){
		getWindowManager().getDefaultDisplay().getMetrics(metrix);
		
		width = metrix.widthPixels;
		height = metrix.heightPixels;
		try{
//			File image = path.createTempFile(file_name,".JPEG" , path);	//�ӽ����ϻ�
			File file = new File(full_path);	//���ϻ�
			fos = new FileOutputStream(file);
//			Bitmap resize = Bitmap.createScaledBitmap(mBitmap, portion, height/(width/portion), true);
			Bitmap resize = Bitmap.createScaledBitmap(mBitmap, width, height, true);
			
			resize.compress(CompressFormat.JPEG, 70, fos);	//
			Log.i(TAG, "���� ������ �ð� ���� �̸� : "+ full_path);
			
//			android 4.4.2���� �ȸ��� > MediaScanner ����ؾ���> �ȱ׷��� gallery�� �ٷιٷ� �� ��
//			sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, Uri.parse(full_path)));
			MediaScanner mscanner = new MediaScanner(getApplicationContext(), file);
		}
		catch (Exception e) {
			Log.e(TAG,"Bitmap to File Error : "+ e.toString());
		}
		finally{
			try{
				fos.close();
			}
			catch(Exception e){
				Log.e(TAG, "fos close ERROR : "+e.toString());
			}
		}
	
		
	}
}
